package com.capgemini.fs.app.ekms.persistence.dao.implementations;

import java.util.List;

import com.capgemini.fs.app.ekms.model.Functionality;
import com.capgemini.fs.app.ekms.persistence.dao.FunctionalityDAO;

public class FunctionalityDAOImpl extends BaseDAOHibernateImpl<Functionality>
		implements FunctionalityDAO {

	public void addFunctionality(Functionality functionality) {
		getHibernateTemplate().save(functionality);
	}

	@SuppressWarnings("unchecked")
	public Functionality getFunctionalityByName(String name) {
		String hql = "from Functionality f where f.functionalityName=?";
		List<Functionality> list = (List<Functionality>) getHibernateTemplate()
				.find(hql, name);
		return list.isEmpty()?null:(Functionality) list.get(0);
	}

	public List<Functionality> getAllFunctionalities() {
		return super.findAll(Functionality.class);
	}

	@SuppressWarnings("unchecked")
	public List<String> getAllFunctionalityCategories() {
		return getHibernateTemplate().findByNamedQuery(
				"getFunctionalityCategory");

	}

	@SuppressWarnings("unchecked")
	public Functionality getFunctionalityByFunctionalityCode(
			String functionalityCode) {
		List<Functionality> functionalities = getHibernateTemplate()
				.findByNamedQueryAndNamedParam("findFunctionalityByCode",
						"functionalityCode", functionalityCode);
		return (functionalities.isEmpty()) ? null : functionalities.get(0);
	}

}
